# Copyright 2022 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test")

# core
yacl_cc_library(
    name = "drbg",
    visibility = ["//visibility:public"],
    deps = [
        ":ic_factory",
        ":native_factory",
        ":openssl_factory",
    ],
)

# private spi
yacl_cc_library(
    name = "spi",
    hdrs = [
        "drbg.h",
    ],
    visibility = ["//visibility:private"],
    deps = [
        "//yacl:secparam",
        "//yacl/base:byte_container_view",
        "//yacl/base:int128",
        "//yacl/crypto/rand/entropy_source",
        "//yacl/utils/spi",
    ],
)

# private openssl drbg impl
yacl_cc_library(
    name = "openssl_factory",
    srcs = [
        "openssl_factory.cc",
    ],
    hdrs = [
        "openssl_factory.h",
    ],
    data = [
        "//yacl/crypto/ossl-provider:prov_shared",  # openssl provider shared lib
    ],
    visibility = ["//visibility:private"],
    deps = [
        ":spi",
        "//yacl/crypto:openssl_wrappers",
        "//yacl/crypto/ossl-provider:helper",  # helper
        "//yacl/crypto/rand/entropy_source",
    ],
    alwayslink = 1,
)

# ic factory
yacl_cc_library(
    name = "ic_factory",
    srcs = [
        "ic_factory.cc",
    ],
    hdrs = [
        "ic_factory.h",
    ],
    data = [
        "//yacl/crypto/ossl-provider:prov_shared",  # openssl provider shared lib
    ],
    visibility = ["//visibility:private"],
    deps = [
        ":spi",
        "//yacl/crypto:openssl_wrappers",
        "//yacl/crypto/ossl-provider:helper",  # helper
        "//yacl/crypto/rand/entropy_source",
        "@com_github_greendow_hash_drbg//:hash_drbg",
    ],
    alwayslink = 1,
)

# native factory
yacl_cc_library(
    name = "native_factory",
    srcs = [
        "native_factory.cc",
    ],
    hdrs = [
        "native_factory.h",
    ],
    data = [
        "//yacl/crypto/ossl-provider:prov_shared",  # openssl provider shared lib
    ],
    visibility = ["//visibility:private"],
    deps = [
        ":spi",
        "//yacl/crypto:openssl_wrappers",
        "//yacl/crypto/block_cipher:symmetric_crypto",
        "//yacl/crypto/hash:hash_utils",
        "//yacl/crypto/ossl-provider:helper",  # helper
        "//yacl/crypto/rand/entropy_source",
    ],
    alwayslink = 1,
)

yacl_cc_test(
    name = "factory_test",
    srcs = ["factory_test.cc"],
    deps = [
        ":drbg",
    ],
)
